
using Qdb.Ext;
using Qdb.Foundation;
using Qdb.Internal;

namespace Qdb.Drs.Qdb
{
	internal class QdbSignatureMap
	{
		private readonly IInternalObjectContainer _stream;

		private readonly Hashtable4 _identities;

		internal QdbSignatureMap(IInternalObjectContainer stream)
		{
			_stream = stream;
			_identities = new Hashtable4();
		}

		internal virtual QdbDatabase Produce(byte[] signature, long creationTime)
		{
			QdbDatabase db = (QdbDatabase)_identities.Get(signature);
			if (db != null)
			{
				return db;
			}
			db = new QdbDatabase(signature, creationTime);
			db.Bind(_stream.Transaction);
			_identities.Put(signature, db);
			return db;
		}

		public virtual void Put(QdbDatabase db)
		{
			QdbDatabase existing = (QdbDatabase)_identities.Get(db.GetSignature());
			if (existing == null)
			{
				_identities.Put(db.GetSignature(), db);
			}
		}
	}
}
